home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / src / plfont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-25  |  2.9 KB  |  121 lines

  1. /* $Id: plfont.c,v 1.17 1994/08/25 04:04:25 mjl Exp $
  2.  * $Log: plfont.c,v $
  3.  * Revision 1.17  1994/08/25  04:04:25  mjl
  4.  * Eliminated unnecessary header file inclusions.
  5.  *
  6.  * Revision 1.16  1994/07/29  20:24:42  mjl
  7.  * References to plfontopen() deleted, in favor of using plLibOpen().
  8.  *
  9.  * Revision 1.15  1994/07/26  21:14:44  mjl
  10.  * Improvements to the way PLplot looks for various files.  Now more
  11.  * consistent and flexible.  In particular, environmentals can be set for
  12.  * locations of each directory (for Tcl, binary, and library files).
  13.  * Contributed by Mark Olesen.
  14. */
  15.  
  16. /*    plfont.c
  17.  *
  18.  *    Font management code.
  19.  *    See the description of plLibOpen() for the search path used in
  20.  *    finding the font files.
  21. */
  22.  
  23. #include "plplotP.h"
  24.  
  25. /* Declarations */
  26.  
  27. short int *fntlkup;
  28. short int *fntindx;
  29. SCHAR *fntbffr;
  30. short int numberfonts, numberchars;
  31. short int indxleng;
  32.  
  33. static short fontloaded = 0;
  34.  
  35. /*----------------------------------------------------------------------*\
  36.  * void plfntld(fnt)
  37.  *
  38.  * Loads either the standard or extended font.
  39. \*----------------------------------------------------------------------*/
  40.  
  41. void
  42. plfntld(PLINT fnt)
  43. {
  44.     static PLINT charset;
  45.     short bffrleng;
  46.     FILE *file;
  47.     PDFstrm *pdfs;
  48.  
  49.     if (fontloaded && (charset == fnt))
  50.     return;
  51.  
  52.     plfontrel();
  53.     fontloaded = 1;
  54.     charset = fnt;
  55.  
  56.     if (fnt)
  57.     file = plLibOpen(PL_XFONT);
  58.     else
  59.     file = plLibOpen(PL_SFONT);
  60.  
  61.     if (file == NULL)
  62.     plexit("Unable to open font file");
  63.  
  64.     pdfs = pdf_finit(file);
  65.     if ( ! pdfs)
  66.     plexit("plfntld: Out of memory while allocating PDF stream data.");
  67.  
  68. /* Read fntlkup[] */
  69.  
  70.     pdf_rd_2bytes(pdfs, (U_SHORT *) &bffrleng);
  71.     numberfonts = bffrleng / 256;
  72.     numberchars = bffrleng & 0xff;
  73.     bffrleng = numberfonts * numberchars;
  74.     fntlkup = (short int *) malloc(bffrleng * sizeof(short int));
  75.     if ( ! fntlkup)
  76.     plexit("plfntld: Out of memory while allocating font buffer.");
  77.  
  78.     pdf_rd_2nbytes(pdfs, (U_SHORT *) fntlkup, bffrleng);
  79.  
  80. /* Read fntindx[] */
  81.  
  82.     pdf_rd_2bytes(pdfs, (U_SHORT *) &indxleng);
  83.     fntindx = (short int *) malloc(indxleng * sizeof(short int));
  84.     if ( ! fntindx)
  85.     plexit("plfntld: Out of memory while allocating font buffer.");
  86.  
  87.     pdf_rd_2nbytes(pdfs, (U_SHORT *) fntindx, indxleng);
  88.  
  89. /* Read fntbffr[] */
  90. /* Since this is an array of char, there are no endian problems */
  91.  
  92.     pdf_rd_2bytes(pdfs, (U_SHORT *) &bffrleng);
  93.     fntbffr = (SCHAR *) malloc(2 * bffrleng * sizeof(SCHAR));
  94.     if ( ! fntbffr)
  95.     plexit("plfntld: Out of memory while allocating font buffer.");
  96.  
  97.     fread((void *) fntbffr, (size_t) sizeof(SCHAR),
  98.       (size_t) (2 * bffrleng), pdfs->file);
  99.  
  100. /* Done */
  101.  
  102.     pdf_close(pdfs);
  103. }
  104.  
  105. /*----------------------------------------------------------------------*\
  106.  * void plfontrel()
  107.  *
  108.  * Release memory for fonts.
  109. \*----------------------------------------------------------------------*/
  110.  
  111. void
  112. plfontrel(void)
  113. {
  114.     if (fontloaded) {
  115.     free_mem(fntindx)
  116.     free_mem(fntbffr)
  117.     free_mem(fntlkup)
  118.     fontloaded = 0;
  119.     }
  120. }
  121.